<div class="box-header with-border">
    <h3 class="box-title">基础设置</h3>
    <!-- /.box-tools -->
</div>
<!-- /.box-header -->
<form role="form" onsubmit="return sub_setting_1()">
    <div class="box-body">
        <div class="form-group" style="overflow:hidden;">
            <div style="float:left;margin-right:10px;">
                <label>邀请码状态</label>
                <input type="checkbox" id="invite_code_state" class="on-off-button" data-size="mini" data-label-width="0" data-off-text="关闭" data-on-text="开启" data-handle-width="40" {$sys['invite_code_state']==2?'':'checked'}>
            </div>
            <div class="checkbox" id="invite_code_state_other_txt" style="float:left;margin:2px;color:{$sys['invite_code_state']==2?'#a7a7a7':'#000000'}"><label><input id="invite_code_state_other" {$sys['invite_code_state']==2?'disabled="disabled"':''} {$sys['invite_code_state']==3?'checked':''} type="checkbox">是否强制使用邀请码</label></div>
        </div>
        <div class="form-group" style="overflow:hidden;">
            <label for="exchange_rate">汇率设置<font color="#d63c28">（金额 = 人民币1元 * {$sys['exchange_rate']}）</font></label>
            <input type="text" value="{$sys['exchange_rate']}" class="form-control" id="exchange_rate" placeholder="汇率设置">
        </div>
        <div class="form-group" style="overflow:hidden;">
            <label for="exchange_rate">倍率设置</label>
            <input type="text" value="{$sys['multiplying_power']}" class="form-control" id="multiplying_power" placeholder="倍率设置">
        </div>
        <div class="form-group" style="overflow:hidden;">
            <label for="once_max_order_num">单次下单最大手数</label>
            <input type="text" value="{$sys['once_max_order_num']}" class="form-control" id="once_max_order_num" placeholder="单次下单最大手数">
        </div>
        <div class="form-group" style="overflow:hidden;">
            <label for="order_fee">下单手续费(%)</label>
            <input type="text" value="{$sys['order_fee']}" class="form-control" id="order_fee" placeholder="下单手续费">
        </div>
    </div>
    <!-- /.box-body -->

    <div class="box-footer">
        <button type="submit" class="btn btn-primary">保存</button>
    </div>
</form>

<script>
    $(function() {
        $("#invite_code_state").on('switchChange.bootstrapSwitch', function(event, state) {
            if (state == true) {
                $("#invite_code_state_other").removeAttr("disabled");
                $("#invite_code_state_other_txt").css("color", "#000000")
            } else {
                $("#invite_code_state_other").attr("disabled", true);
                $("#invite_code_state_other_txt").css("color", "#a7a7a7")
            }
        });
    });
    function sub_setting_1(){
        var invite_code_state = 1;
        var flag = $("#invite_code_state").bootstrapSwitch("state");
        if (flag == false) {
            invite_code_state = 2;
        } else {
            if($("#invite_code_state_other").is(':checked')) {
                invite_code_state = 3;
            }
        }

        var exchange_rate = $("#exchange_rate").val();
        if (exchange_rate < 0) {
            $.scojs_message("汇率设置不能为空", $.scojs_message.TYPE_ERROR);
            return false;
        }

        var multiplying_power = $("#multiplying_power").val();
        if (multiplying_power < 0) {
            $.scojs_message("倍率设置不能为空", $.scojs_message.TYPE_ERROR);
            return false;
        }

        var once_max_order_num = $("#once_max_order_num").val();
        if (once_max_order_num < 0) {
            $.scojs_message("单次下单最大手数不能为空", $.scojs_message.TYPE_ERROR);
            return false;
        }
        var order_fee = $("#order_fee").val();
        if (order_fee <  0) {
            $.scojs_message("下单手续费不能为空", $.scojs_message.TYPE_ERROR);
            return false;
        }
        $.ajax({
            type:"POST",
            url : '__ADMIN__/'+moduleName+'/setting',
            dataType:"json",
            data:{
                id:1,
                invite_code_state:invite_code_state,
                exchange_rate:exchange_rate,
                multiplying_power:multiplying_power,
                once_max_order_num:once_max_order_num,
                order_fee:order_fee
            },
            beforeSend:showLoad,
            success:function(msg) {
                if (msg.code == 0)
                    $.scojs_message(msg.msg, $.scojs_message.TYPE_OK);
                else
                    $.scojs_message(msg.msg, $.scojs_message.TYPE_ERROR);
                hideLoad();
            }
        });

        return false;
    }
</script>